package com.cloudcc.cloudframe.ui.viewgroup.refresh;

import android.view.View;
import android.widget.AbsListView;

/**
 * 默认的 下拉刷新的 头部功能接口
 * 
 * @author seven
 * 
 */
public abstract class PtrDefaultHandler implements PtrHandler {

	/**
	 * 检测是不是还能向上滑动 listview滑动到最上面的一个child
	 * 
	 * @param view
	 * @return
	 */
	public static boolean canChildScrollUp(View view) {
		if (android.os.Build.VERSION.SDK_INT < 14) {// 4.0一下
			if (view instanceof AbsListView) {
				final AbsListView absListView = (AbsListView) view;
				return absListView.getChildCount() > 0
						&& (absListView.getFirstVisiblePosition() > 0 || absListView
								.getChildAt(0).getTop() < absListView
								.getPaddingTop());
			} else {
				return view.getScrollY() > 0;
			}
		} else {// 4.0以上
			return view.canScrollVertically(-1);
		}
	}

	/**
	 * Default implement for check can perform pull to refresh 检测内容是否 能被刷新
	 * listview的时候常用
	 * 
	 * @param frame
	 * @param content
	 * @param header
	 * @return
	 */
	public static boolean checkContentCanBePulledDown(PtrFrameLayout frame,
			View content, View header) {
		return !canChildScrollUp(content);
	}

	@Override
	public boolean checkCanDoRefresh(PtrFrameLayout frame, View content,
			View header) {
		return checkContentCanBePulledDown(frame, content, header);
	}
}